package com.yoomiito.app.gift;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseActPresenter;
import com.yoomiito.app.base.BaseFragment;
import com.yoomiito.app.base.BaseLazyFragmentPresenter;
import com.yoomiito.app.model.gift.GiftGoods;
import com.yoomiito.app.model.gift.GiftGoodsList;
import com.yoomiito.app.model.gift.GiftType;
import com.yoomiito.app.net.YmApi;
import com.yoomiito.app.ui.fragment.GiftFragment;
import com.yoomiito.app.ui.gift.GiftActivity;

import java.util.List;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;
import retrofit2.http.Query;

public class GiftFragmentPresenter extends BaseLazyFragmentPresenter<GiftFragment> {

    public GiftFragmentPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getVipGiftGoods(int sort, int page, long giftType,int type){
        YmApi.getYmService()
                .getVipGiftGoods(sort+"",page,giftType,type,"")
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<GiftGoodsList>(handleException()) {
                    @Override
                    public void onSuccess(GiftGoodsList giftGoodsList) {
                        getV().showGift(giftGoodsList);
                        getV().dismissLoading();
                    }

                    @Override
                    public void onFail(ApiException error) {
                        getV().dismissLoading();
                    }
                });
    }



    public void getVipGiftGood(int priceSort, int page, long type,int categorizeId,int salesSort){
        YmApi.getYmService()
                .getVipGiftGood(priceSort,page,type,categorizeId,salesSort,10)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<GiftGoodsList>(handleException()) {
                    @Override
                    public void onSuccess(GiftGoodsList giftGoodsList) {
                        getV().showGift(giftGoodsList);
                        getV().dismissLoading();
                    }

                    @Override
                    public void onFail(ApiException error) {
                        getV().dismissLoading();
                    }
                });
    }

    public void getGiftType(int id){
        YmApi.getYmService()
                .getGiftType(id)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<List<GiftType>>(handleException()) {
                    @Override
                    public void onSuccess(List<GiftType> giftTypes) {
                        getV().setType(giftTypes);
                    }

                    @Override
                    public void onFail(ApiException error) {

                    }
                });
    }


}
